package com.pwt.utils;

import com.alibaba.fastjson.JSONObject;
import com.pwt.model.CloudMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;

/**
 * @author dw
 * @date 2022/1/18 18:48
 * @Description
 */
@Component
public class CloudHomeUtils {

    private Logger logger = LoggerFactory.getLogger(CloudMessage.class);

    @Value("${HomeCloud.JobNo}")
    private String JobNo;

    @Value("${HomeCloud.url}")
    private String url;


    public String sendMessage(List<String> receive,String msg){
        CloudMessage cloudMessage = new CloudMessage();
        cloudMessage.setSenderJobNo(JobNo);
        cloudMessage.setReceivejobNo(receive);
        cloudMessage.setContent(msg);
        try {
            return HttpUtils.doPost(url, JSONObject.toJSONString(cloudMessage));
        } catch (IOException e) {
            e.printStackTrace();
            logger.error("消息推送失败！"+receive.toString());
        }
        return null;
    }
}
